﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EMall.OrderService.Orders
{
    public class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
    {
        public void Configure(EntityTypeBuilder<Order> builder)
        {
            builder.ToTable("Orders");
            builder.HasKey(p => p.Id);
            builder.Property(p => p.OrderNumber).IsRequired();
            builder.Property(p => p.CreatedTime).IsRequired();
            builder.OwnsOne(p => p.Buyer);
            builder.OwnsOne(p => p.Address);
        }
    }
    public class OrderItemEntityTypeConfiguration : IEntityTypeConfiguration<OrderItem>
    {
        public void Configure(EntityTypeBuilder<OrderItem> builder)
        {
            builder.ToTable("OrderItems");
            builder.HasKey(p => p.Id);
            builder.Property<int>("OrderId").IsRequired();
            builder.Property(p => p.ProductId).IsRequired();
            builder.Property(p => p.ProductName);
            builder.Property(p => p.UnitPrice).IsRequired();
            builder.Property(p => p.Quantity).IsRequired();
        }
    }
}